package junior.Recursion递推;

public class YangHuiTriangular {
    static int[][] a= new int[100][100];  //类的全局变量
    public static void main(String[] args) {
        YangHuiTriangular yht = new YangHuiTriangular();
        yht.recursion(a,10);
    }
    // 递推算法
    public void recursion(int[][] a,int n){
        for (int i = 0; i < n; i++) //初试化
            a[i][0]=1;
        // 递推计算所有行的值
        for (int i = 1; i < n; i++) {
            for (int j = 1; j <= i; j++) {
                a[i][j] = a[i-1][j-1]+a[i-1][j];  //左加右
            }
        }
        System.out.println("显示结果：");
        for (int i = 0; i < n; i++) {
            for (int k = 0; k < n-i-1; k++) {
                System.out.print("\t");
            }
            for (int j = 0; j <= i; j++) {
                System.out.print(a[i][j]+"\t\t");
            }
            System.out.println();
        }
    }
}
